<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- 车型选择 -->
<div class="content-show" id="searchDiv" style="display: none;">
 	<div class="searchtop">
		<input type="text"  class="form-control smallicon  fixedsearch"  id="searchname" name="searchname" placeholder="车型名称" onkeyup="carcho(true);" onafterpaste="carcho(true);">
	</div>
	<ul class="cho-ul" id="searchUl"></ul>
</div>
<!-- 车型选择-->
<script type="text/javascript">
 //执行了某次查询，并且已经完成查询
 var preCarListAjax;
 var exete = true;
 function carcho(hasOpen, name){
	if(name) {
		searchCar(hasOpen, name);
	} else {
		if(exete) {
			exete = false;
			setTimeout(function(){
				exete = true;
			}, 500);
			searchCar(hasOpen,name);
		}
	}
  }

 function removeDuan(){
	 var minZindex = 0;
		var $shadeDiv;
		$('.layui-layer-shade').each(function(i,obj){
			var thisIndex = $(this).css('z-index');
			if(i == 0) {
				minZindex = thisIndex;
				$shadeDiv = $(this);
			} else {
				if(minZindex > thisIndex) {
					$shadeDiv.remove();
					$shadeDiv = $(this);
					minZindex = thisIndex;
				} else {
					$(this).remove();
				}
			}
		});
		$('.layui-layer-move').each(function(i,obj){
			$(this).remove();
		});
 }
 
 function searchCar(hasOpen, name) {
	    var name = name || ($('#searchname').val() || '');
	    var currentCarListAjax = $.dpAjax({
    		show:false,
    		url:'${basePath}/JuheCarController/carModelList',
    		data:{nameCarModel:name,rows:20},
			success: function(datas){
		 		var records = datas.result.rows;
		 		$searchUl = $('#searchUl');
		 		$searchUl.empty();
		 		if(records && records.length > 0) {
		 			var content = '';
			 		for(var i=0;i< records.length; i++){
			 			var record = records[i];
		 				/* content +='<a href="javascript:choice(\''+record.carBrand+'\', \''+record.carSeries+'\', \''+record.carModel+'\', \''+record.nameCarBrand+'\', \''+record.nameCarSeries+'\', \''+record.nameCarModel+'\');"><li><span class="li-carname"><lable>车型：</lable>' + record.nameCarModel +'</span>&nbsp;&nbsp;<lable>编号：</lable>' + record.carModel +'</li></a>'; */  
			 			   content +='<a href="javascript:choice(\''+record.carBrand+'\', \''+record.carSeries+'\', \''+record.carModel+'\', \''+record.nameCarBrand+'\', \''+record.nameCarSeries+'\', \''+record.nameCarModel+'\', \''+record.priceNewcar + '\');"><li><span class="li-carname"><lable>车型：</lable>' + record.nameCarModel +'</span></li></a>';	
			 		}
			 		$searchUl.html(content);
		 		}
		 		
		 		if(!hasOpen) {
		 			$("#searchname").val(name);
					layer.open({
					  title:'车型选择',
					  type: 1,
					  area: ['620px', '500px'], //宽高
					  content: $('#searchDiv')
					}); 
					removeDuan();
					$("#searchname").focus();
		 		}
		 		if(name != $("#searchname").val()){//完成时，并不是最终的查询条件
		 			setTimeout(function(){
		 				searchCar(true);
		 			}, 500);
		 		}
			 }
    	 });
	    if(preCarListAjax) {
	    	preCarListAjax.abort();
	    }
	    preCarListAjax = currentCarListAjax;
    }
	var choice = function(carBrand, carSeries, carModel, nameCarBrand, nameCarSeries,nameCarModel,priceNewcar)
	{
		document.getElementById("carBrand").value = carBrand;
		document.getElementById("carSeries").value = carSeries;
		document.getElementById("carModel").value = carModel;
		document.getElementById("nameCarBrand").value = nameCarBrand;
		document.getElementById("nameCarSeries").value = nameCarSeries;
		document.getElementById("nameCarModel").value = nameCarModel;
		document.getElementById("carName").value = nameCarModel;
		document.getElementById("priceNewcar").value = priceNewcar;
		layer.closeAll();
	}
</script>